package com.azzcs.server;

import com.azzcs.Catalina;
import com.azzcs.lifecycle.LifecycleBase;
import com.azzcs.service.Service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: wzg
 * @Date: 2021/1/7 下午4:16
 */
public class StandardServer extends LifecycleBase implements Server{
    private int port = 8080;
    private Catalina catalina;
    List<Service> services = new CopyOnWriteArrayList<>();

    @Override
    public int getPort() {
        return port;
    }

    @Override
    public void setPort(int port) {
        this.port = port;
    }

    @Override
    public Catalina getCatalina() {
        return catalina;
    }

    @Override
    public void setCatalina(Catalina catalina) {
        this.catalina = catalina;
    }

    @Override
    public void addService(Service service) {
        this.services.add(service);
    }

    @Override
    public void removeService(Service service) {
        this.services.remove(service);
    }

    @Override
    protected void initInternal() {
        for (Service service : services) {
            service.init();
        }
    }

    @Override
    protected void startInternal() {
        for (Service service : services) {
            service.start();
        }
    }
}
